package com.deram.ctin.serv.system.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.deram.ctin.dependencies.serv.utils.MybatisUtils;
import com.deram.ctin.serv.system.entity.SystemSearch;
import com.deram.ctin.serv.system.filter.SystemSearchFilter;
import com.deram.ctin.serv.system.mapper.SystemSearchMapper;
import com.deram.ctin.serv.system.service.SystemSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Wrapper;
import java.util.List;

/**
 * Created by xhw on 2017/09/13.
 */

@Service
public class SystemSearchServiceImpl implements SystemSearchService {


    @Autowired
    private SystemSearchMapper systemSearchMapper;

    @Override
    public SystemSearch find(Long id) {
        return systemSearchMapper.selectById(id);
    }

    @Override
    public List<SystemSearch> list(SystemSearchFilter filter) {
        EntityWrapper<SystemSearch> ew = createEntityWrapper(filter);
        return systemSearchMapper.selectList(ew);
    }

    private EntityWrapper<SystemSearch> createEntityWrapper(SystemSearchFilter filter) {
        SystemSearch entity = new SystemSearch();
        entity.setType(filter.getType());
        if(null == filter.getOrderBy()){
            filter.setOrderBy("sort, id");
        }
        EntityWrapper<SystemSearch> ew = new EntityWrapper<SystemSearch>(entity);
        MybatisUtils.fillEntityWrapper(ew, filter);
        return ew;
    }
}
